home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / readin.arc / READIN.PRO
Encoding:
Text File  |  1985-11-06  |  1.6 KB  |  73 lines

  1.  %%%
  2.  %%%  the read_in predicates
  3.  %%%
  4.  
  5.  %%%     tested using Arity Prolog V3.2
  6.  
  7.  %%%     Donated by:
  8.  %%%
  9.  %%%          Whitfield Gregg
  10.  %%%          Nourse, Gregg & Browne, Inc.
  11.  %%%          61 Jane St.
  12.  %%%          New York, NY 10014
  13.  
  14.  %%%     Help from: Deyi Li
  15.  
  16.  %%%
  17.  %%% The read_in goal will take input from the use's terminal
  18.  %%%     and return the input line as a list of atoms.
  19.  %%%
  20.  %%%     for example:
  21.  %%%
  22.  %%%      read_in(Z).
  23.  %%%       this is a test
  24.  %%%     Z = [this,is,a,test]
  25.  %%%
  26.  
  27. read_in([W|Ws]) :-
  28.          get0(C),
  29.          readword(C,W,C1),
  30.          w \== [],
  31.          restsent(C1,Ws),
  32.          !.
  33.  
  34. read_in([]) :- !.       % An empty line
  35.  
  36. restsent(13,[]) :- !.   % the rest of the sentence was empty
  37.  
  38. restsent(C,[W1|Ws]) :-
  39.          readword(C,W1,C1),
  40.          W1 \== [],
  41.          restsent(C1,Ws).
  42.  
  43. restsent(_,[]) :- !.
  44.  
  45. readword(C,W,C2) :-
  46.          in_word(C,NewC),
  47.          !,
  48.          get0(C1),
  49.          restword(C1,Cs,C2),
  50.          name(W,[NewC|Cs]).
  51.  
  52. readword(13,[],_) :- !.      % the first is a 'return'
  53.  
  54. readword(_,W,C2) :-
  55.          get0(C1),
  56.          readword(C1,W,C2).
  57.  
  58. restword(C,[NewC|Cs],C2) :-
  59.          in_word(C,NewC),
  60.          !,
  61.          get0(C1),
  62.          restword(C1,Cs,C2).
  63.  
  64. restword(C,[],C).
  65.  
  66.  %%% table of valid characters within a word.
  67.  
  68. in_word(C,C) :-    C > 96,  C < 123.
  69. in_word(C,C) :-    C > 64,  C < 91.
  70. in_word(C,C) :-    C > 46,  C < 58.
  71. in_word(C,C) :-    C > 38,  C < 44.
  72. in_word(C,C) :-    C > 59,  C < 63.
  73.